package com.yuejian_06.yuejian_06.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.Listener.MeListener;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.bean.SuccessBean;
import com.yuejian_06.yuejian_06.model.MeModel;

import static com.yuejian_06.yuejian_06.R.id.back_money;

public class OrdercInfoActivity extends BaseActivity {
    private TextView sign_id,name,price,starttime1,stoptime,intro;
    private ImageView pic;
    private ImageButton back;
    private Button back_money;

    @Override
    void initViews() {

    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_orderc_info);
        initView();
        initEvent();
    }
    private void initView(){
        sign_id = (TextView) findViewById(R.id.sign_id);
        name = (TextView) findViewById(R.id.name);
        price = (TextView) findViewById(R.id.price);
        starttime1 = (TextView) findViewById(R.id.starttime1);
        stoptime = (TextView) findViewById(R.id.stoptime);
        intro = (TextView) findViewById(R.id.intro);
        pic = (ImageView) findViewById(R.id.pic);
        back = (ImageButton) findViewById(R.id.back);
        back_money = (Button) findViewById(R.id.back_money);

        Intent intent = getIntent();
        sign_id.setText(intent.getStringExtra("sign_id"+""));
        name.setText(intent.getStringExtra("name"+""));
        price.setText(intent.getStringExtra("price"+""));
        starttime1.setText(intent.getStringExtra("starttime1"+""));
        stoptime.setText(intent.getStringExtra("stoptime"+""));
        intro.setText(intent.getStringExtra("intro"+""));
        if (!"".equals(intent.getStringExtra("pic")))
            Picasso.with(OrdercInfoActivity.this).load("http://10.0.2.2/yuejian/Public/coursepics/"+intent.getStringExtra("pic")).into(pic);
    }

    private void initEvent(){
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        back_money.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(OrdercInfoActivity.this);
                builder.setIcon(R.drawable.heart_p);
                builder.setTitle(R.string.del);
                builder.setMessage(R.string.del_order);
                builder.setPositiveButton(R.string.postive_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String sign_id1 = sign_id.getText().toString();
                        MeModel meModel = new MeModel();
                        meModel.getDelOrder(sign_id1,meListener);
                    }
                });

                builder.setNegativeButton(R.string.negative_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(OrdercInfoActivity.this,"已经取消申请",Toast.LENGTH_SHORT).show();
                    }
                });

                builder.setCancelable(false);
                AlertDialog dialog=builder.create();
                dialog.show();
            }
        });
    }


    private MeListener<SuccessBean> meListener = new MeListener<SuccessBean>() {
        @Override
        public void onResponse(SuccessBean o) {
            Toast.makeText(OrdercInfoActivity.this,"申请退款成功",Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(OrdercInfoActivity.this,OrderActivity.class);
            startActivityForResult(intent,1);
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(OrdercInfoActivity.this,"申请退款失败",Toast.LENGTH_SHORT).show();
        }
    };
}